
<%
	// Retrieve session variables.
	String username = request.getParameter("username");
	String password = request.getParameter("password");

	// Getting information and updating the database.
	java.sql.Connection conn = null;
	try {
		String myJDBCDriver = (String) session.getAttribute("myJDBCDriver");
		String myURL = (String) session.getAttribute("myURL");
		String myUserID = (String) session.getAttribute("myUserID");
		String myPassword = (String) session.getAttribute("myPassword");

		// Connect to the database.
		Class.forName(myJDBCDriver).newInstance();
		java.util.Properties sysprops = System.getProperties();
		sysprops.put("user", myUserID);
		sysprops.put("password", myPassword);
		conn = java.sql.DriverManager.getConnection(myURL, sysprops);

		java.sql.Statement statement = conn.createStatement();
		java.sql.ResultSet rs = statement.executeQuery("SELECT username, type FROM users WHERE username = '" + username
				+ "' AND password = '" + password + "'");
		if (rs.next()) {
			// Credentials are correct.
			session.setAttribute("user", username);
			session.setAttribute("type", rs.getString("type"));
			response.sendRedirect("index.jsp");
		} else {
			// The username and password combination does not exist.
			session.setAttribute("errors", "* This username and password combination was not found in the database.");
			session.setAttribute("username", username);
			response.sendRedirect("login.jsp");
		}
	} catch (Exception e) {
		e.printStackTrace();
		out.print(e.toString());
	} finally {
		try {
			conn.close();
		} catch (Exception ee) {
		}
	}
%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<title>Scholar Aide</title>
</head>
<body>
	<jsp:include page="/includes/header.jsp" />
	<div id="wrapper">
		<div id="content"></div>
	</div>
	<jsp:include page="/includes/footer.jsp" />
</body>
</html>